package com.oa.gongwen.dao;

import com.oa.gongwen.entity.Gongwen;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;


@MapperScan
public interface GongwenMapper {
    @Delete({
        "delete from gongwen",
        "where gw_id = #{gwId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer gwId);

    @Insert({
        "insert into gongwen (gw_id, title, ",
        "author, ",
        "state,grade, ",
        " content,g_address)",
        "values (#{gwId,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, ",
        "#{author,jdbcType=VARCHAR}, ",
        "#{state,jdbcType=INTEGER}, #{grade,jdbcType=INTEGER}, ",
        " #{content,jdbcType=LONGVARCHAR},#{gwAddress,jdbcType=VARCHAR})"
    })
    int insert(Gongwen record);

    int insertSelective(Gongwen record);

    @Select({
    	"select count(state) from gongwen where state=1;"
    })
    int count();
    
    @Select({
    	"select count(state) from gongwen where state=2;"
    })
    int count2();
    @Select({
        "select",
        "gw_id, title, author, accept_trust, state, agree, grade, audit, audit_grade, ",
        "remove, content",
        "from gongwen",
        "where state = #{state,jdbcType=INTEGER} and author=#{author,jdbcType=VARCHAR} order by gw_id desc limit #{pageno},10"
    })
    @ResultMap("com.oa.gongwen.dao.GongwenMapper.ResultMapWithBLOBs")
    List<Gongwen> selectByPrimaryKeys(@Param("state")Integer state,@Param("author")String use,@Param("pageno")Integer pageno);
    @Select({
        "select",
        "gw_id, title, author, accept_trust, state, agree, grade, audit, audit_grade, ",
        "remove, content",
        "from gongwen",
        "where state = #{state,jdbcType=INTEGER} order by gw_id desc limit #{pageno},10"
    })
    @ResultMap("com.oa.gongwen.dao.GongwenMapper.ResultMapWithBLOBs")
    List<Gongwen> selectByPrimaryKey(@Param("state")Integer state,@Param("pageno")Integer pageno);

@Select({
        "select",
        "gw_id, title, author, accept_trust, state, agree, grade, audit, audit_grade, ",
        "remove, content",
        "from gongwen",
        "where state = #{state,jdbcType=INTEGER} and agree=#{agree,jdbcType=INTEGER} order by gw_id desc"
    })
    @ResultMap("com.oa.gongwen.dao.GongwenMapper.ResultMapWithBLOBs")
    List<Gongwen> selectBydo(@Param("state")Integer state,@Param("agree")int agree);
    
    @Select({
        "select",
        "gw_id, title, author, accept_trust, state, agree, grade, audit, audit_grade, ",
        "remove, content",
        "from gongwen",
        "where gw_id= #{gwId,jdbcType=INTEGER}"
    })
    @ResultMap("com.oa.gongwen.dao.GongwenMapper.ResultMapWithBLOBs")
    Gongwen selectById(Integer id);
    
    @Select({
        "select",
        "gw_id, title, author, accept_trust, state, agree, grade, audit, audit_grade, ",
        "remove, content",
        "from gongwen",
        "where author = #{author} order by gw_id desc limit #{pageno},10"
    })
    @ResultMap("com.oa.gongwen.dao.GongwenMapper.ResultMapWithBLOBs")
    List<Gongwen> selectGWBypageno(@Param("author")String author,@Param("pageno")Integer pageno);

    int updateByPrimaryKeySelective(Gongwen gongwen);

    @Update({
        "update gongwen",
        "set title = #{title,jdbcType=VARCHAR},",
          "author = #{author,jdbcType=VARCHAR},",
          "accept_trust = #{acceptTrust,jdbcType=VARCHAR},",
          "state = #{state,jdbcType=INTEGER},",
          "agree = #{agree,jdbcType=INTEGER},",
          "grade = #{grade,jdbcType=INTEGER},",
          "audit = #{audit,jdbcType=INTEGER},",
          "audit_grade = #{auditGrade,jdbcType=VARCHAR},",
          "remove = #{remove,jdbcType=INTEGER},",
          "content = #{content,jdbcType=LONGVARCHAR}",
        "where gw_id = #{gwId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(Gongwen record);

    @Update({
        "update gongwen",
        "set title = #{title,jdbcType=VARCHAR},",
          "author = #{author,jdbcType=VARCHAR},",
          "accept_trust = #{acceptTrust,jdbcType=VARCHAR},",
          "state = #{state,jdbcType=INTEGER},",
          "agree = #{agree,jdbcType=INTEGER},",
          "grade = #{grade,jdbcType=INTEGER},",
          "audit = #{audit,jdbcType=INTEGER},",
          "audit_grade = #{auditGrade,jdbcType=VARCHAR},",
          "remove = #{remove,jdbcType=INTEGER}",
        "where gw_id = #{gwId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Gongwen record);
}